package dm.ast;

import java.util.List;

/**
 * @author weihuixin
 * @date 2024/4/1
 * @Description
 */
public abstract class DmTableSource extends DmASTNode{
    String alias = null;  //别名

    public String schemaOf = null;   //模式名
    public String name = null;    //表名
    public List<DmColumn> cols = null;  //包含列名
    public boolean isSubSelect = false;

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getSelectName(){
        if(alias != null){  //如果有别名，使用别名
            return alias;
        }else {
            return getFullName();
        }
    }

    public String getFullName(){
        if(schemaOf == null){
            return name;
        }else {
            return schemaOf + "." + name;
        }
    }

    //是否包含字符类型的列
    public boolean containChar(){
        boolean flag = false;
        for (DmColumn col : cols) {
            if(col.reType == DmDataType.CHAR || col.reType == DmDataType.CLOB){
                flag = false;
            }
        }
        return flag;
    }

    //表中增加列
    public abstract void addColumn(DmColumn col);
}
